﻿package rd.hardcore 
{
	import flash.desktop.NativeApplication;
	import flash.desktop.SystemTrayIcon;
	import flash.display.InteractiveObject;
	import flash.events.ContextMenuEvent;
	import flash.events.EventDispatcher;
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	/**
	 * Le menu le plus h¤t
	 * @author Thibault Perret
	 */
	public class HardMenu extends EventDispatcher
	{
		private var closeItem:ContextMenuItem;
		private var miniItem:ContextMenuItem;
		
		public function HardMenu(stage:InteractiveObject) 
		{
			var ct:ContextMenu = new ContextMenu();
			
			//miniItem = new ContextMenuItem("Minimize");
			closeItem = new ContextMenuItem("Close");
			//ct.addItem(miniItem);
			ct.addItem(closeItem);
			closeItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemClick);
			//miniItem.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, itemClick);
			
			stage.contextMenu = ct;
			
			if (NativeApplication.supportsSystemTrayIcon) {
				var sysTray:SystemTrayIcon = NativeApplication.nativeApplication.icon as SystemTrayIcon;
				sysTray.tooltip = "Hardocre application";
				sysTray.menu = ct;
			}
		}
		
		private function itemClick(e:ContextMenuEvent):void 
		{
			switch(e.currentTarget) {
				case closeItem:
					NativeApplication.nativeApplication.exit();
					break;
			}
			
		}
		
	}

}